package com.vpen.server.http;

import com.vpen.server.http.handler.GeneralResponseWriter;
import com.vpen.server.http.handler.HttpServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;



/**
 * 描述
 *
 * @author 韦鹏
 * @date 2024/4/5 22:38
 */
@Slf4j
@Component
public class HttpChannelInitializerImpl extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel channel) {
         ChannelPipeline pipeline = channel.pipeline();

        pipeline
                .addLast(new GeneralResponseWriter())
                .addLast( new HttpResponseEncoder())
        ;

        pipeline.addLast(new HttpRequestDecoder());
        pipeline.addLast(new HttpObjectAggregator(512*1024));
        pipeline.addLast(new HttpServerHandler());
        log.debug("hello http ");

    }
}
